package com.mzj.saas.mservice.smartlock.controller;

import com.haixiaoke.saas.repository.pojo.SmartLock;
import com.mzj.saas.mservice.smartlock.service.haixiaoke.SmartLockHxkCallBackService;
import com.mzj.saas.mservice.smartlock.service.huixiangjia.SmartLockHxjCallBackService;
import com.mzj.saas.mservice.smartlock.service.luoke.SmartLockLkCallBackService;
import com.mzj.saas.mservice.smartlock.service.ruanku.SmartLockCallBackService;
import com.mzj.saas.mservice.smartlock.service.tianwanghulian.SmartLockTwhlCallBackService;
import com.mzj.saas.mservice.smartlock.service.xizhao.SmartLockXzCallBackService;
import com.mzj.saas.mservice.smartlock.service.yaluete.SmarkLockYltEventHandleService;
import com.mzj.saas.mservice.smartlock.service.yaluete.SmartLockYltCallBackService;
import com.mzj.saas.mservice.smartlock.service.youdian.SmartLockYdCallBackService;
import com.mzj.saas.mservice.smartlock.vo.LockCallBackVO;
import com.mzj.saas.mservice.smartlock.vo.SmartLockCallBackVO;
import com.mzj.saas.mservice.smartlock.vo.haixiaoke.HxkCallBack;
import com.mzj.saas.mservice.smartlock.vo.huixiangjia.HuiXiangJiaCallBack;
import com.mzj.saas.mservice.smartlock.vo.luoke.LuoKeCallBack;
import com.mzj.saas.mservice.smartlock.vo.tianwanghulian.TwhlCallBackVO;
import com.mzj.saas.mservice.smartlock.vo.yaluete.YltCallBackVO;
import com.mzj.saas.mservice.smartlock.vo.youdian.ydCallBackVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 智能锁回调/事件处理
 */
@Controller
@RequestMapping("device")
public class SmartLockCallBackController {

    @Autowired
    private SmartLockCallBackService smartLockCallBackService;
    @Autowired
    private SmartLockXzCallBackService smartLockXzCallBackService;
    @Autowired
    private SmartLockYltCallBackService smartLockYltCallBackService;
    @Autowired
    private SmarkLockYltEventHandleService smarkLockYltEventHandleService;
    @Autowired
    private SmartLockTwhlCallBackService smartLockTwhlCallBackService;
    @Autowired
    private SmartLockYdCallBackService smartLockYdCallBackService;
    @Autowired
    private SmartLockHxkCallBackService smartLockHxkCallBackService;
    @Autowired
    private SmartLockLkCallBackService smartLockLkCallBackService;
    @Autowired
    private SmartLockHxjCallBackService smartLockHxjCallBackService;

    /**
     * http://git.cloud.roombanker.cn/doc/api-doc/blob/master/open-api/%E5%AF%B9%E5%A4%96%E5%BC%80%E6%94%BE%E6%8E%A5%E5%8F%A3.md#-905
     * 软库-智能锁回调url
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("lockCallback")
    @ResponseBody
    public Map<String, Object> lockCallback(@RequestBody LockCallBackVO vo) {
        return smartLockCallBackService.lockCallback(vo);
    }

    /**
     * 软库/熙照-账单过期冻结/解冻智能锁
     *
     * @param lockIds 智能锁ids
     * @param type    冻结标识 ：job-executor-frozen  解冻标识：  job-executor-thaw
     *//*
    @PostMapping("backlogItemLock")
    @ResponseBody
    public void backlogItemLock(@RequestBody List<Long> lockIds, @RequestParam(required = false) String type) {
        smartLockCallBackService.backlogItemLock(lockIds, type);
    }*/


    /**
     * 软库-回调事件处理
     *
     * @param vo
     * @author shun
     * @date 2021年6月25日
     */
    @PostMapping("callBackType")
    @ResponseBody
    public void callBackType(@RequestBody LockCallBackVO vo) {
        smartLockCallBackService.callBackType(vo);
    }

    /**
     * 熙照-智能锁回调url
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @RequestMapping("/xz/callback")
    @ResponseBody
    public Map<String, Object> xzLockCallback(@RequestBody SmartLockCallBackVO vo) {
        return smartLockXzCallBackService.lockCallback(vo);
    }

    /**
     * 软库/熙照-账单过期冻结/解冻智能锁
     *
     * @param lockIds 智能锁ids
     * @param type    冻结标识 ：job-executor-frozen  解冻标识：  job-executor-thaw
     */
    @PostMapping("freezeAllLock")
    @ResponseBody
    public void freezeAllLock(@RequestBody Map<String, List<Long>> map, @RequestParam(required = false) String type) {
        smartLockCallBackService.backlogItemLock(map, type);
    }

    /**
     * 亚略特-日志回调
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @RequestMapping("/ylt/log")
    @ResponseBody
    public Map<String, Object> yltLockCallback(@RequestBody YltCallBackVO vo) {
        return smartLockYltCallBackService.lockCallback(vo);
    }

    /**
     * 天网互联-日志回调
     *
     * @param vo
     * @return
     */
    @PostMapping("/twhl/log")
    @ResponseBody
    public String twhlLockCallback(@RequestBody TwhlCallBackVO vo) {
        return smartLockTwhlCallBackService.lockCallback(vo);
    }

    /**
     * 优电-日志回调
     *
     * @param vo
     * @return
     */
    @PostMapping("/yd/log")
    @ResponseBody
    public  Map<String, Object> ydLockCallback(@RequestBody ydCallBackVo vo) {
        return smartLockYdCallBackService.lockCallback(vo);
    }

    @PostMapping("/devices")
    @ResponseBody
    public Map<String, Object> devices(@RequestBody HxkCallBack hxkCallBack){
        return smartLockHxkCallBackService.devices(hxkCallBack);
    }

    @PostMapping("/deviceOpenRecords")
    @ResponseBody
    public Map<String, Object> hxkOpenCallBack(@RequestBody HxkCallBack hxkCallBack){
        return smartLockHxkCallBackService.openCallBack(hxkCallBack);
    }

    /**
     * 设备管理平台同步删除数据
     * @param smartLock
     * @param authorization
     * @return
     */
    @PostMapping("/deleteAuth")
    @ResponseBody
    public Map<String, Object> deleteAuth(@RequestBody SmartLock smartLock,@RequestHeader("Authorization") String authorization){
        return smartLockHxkCallBackService.deleteAuth(smartLock,authorization);
    }

    /**
     * 络克锁日志回调
     * @param luoKeCallBack 回调数据
     * @return
     */
    @PostMapping("/lk/callBack")
    @ResponseBody
    public Map<String, Object> lkCallBack(@RequestBody LuoKeCallBack luoKeCallBack){
        return smartLockLkCallBackService.callBack(luoKeCallBack);
    }

    /**
     * 慧享佳锁日志回调
     * @param huiXiangJiaCallBack 回调数据
     * @return
     */
    @PostMapping("/hxj/callBack")
    @ResponseBody
    public Map<String, Object> hxjCallBack(@RequestBody HuiXiangJiaCallBack huiXiangJiaCallBack){
        return smartLockHxjCallBackService.callBack(huiXiangJiaCallBack);
    }
}
